package com.zzw.grpc;

import io.grpc.CallOptions;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

/**
 * @author Administrator
 */
public class DefaultGrpcClient {

    private final RecEverGrpc.RecEverBlockingStub blockingStub;

    public DefaultGrpcClient(GrpcClientProperties clientProperties) {
        ManagedChannel channel = ManagedChannelBuilder.forAddress(clientProperties.getHost(), clientProperties.getPort()).usePlaintext().build();
        blockingStub = new RecEverGrpc.RecEverBlockingStub(channel, CallOptions.DEFAULT);
    }

    public RecEverything.RecEveResponse process(RecEverything.RecEveRequest request) {
        return blockingStub.recEve(request);
    }

    public RecEverything.RecEveRequest buildRequest(String type, String request) {
        return RecEverything.RecEveRequest.newBuilder().setType(type).setRequest(request).build();
    }
}
